$(document).ready(function() {
    $('#submit_parent').click(function() {
        var validation = $("#createParentForm").validationEngine('validate')
	if (validation) {
	$.ajax({
            type: "POST",
            url: "adapter/parentCreation.php",
            data: $('form#createParentForm').serialize(),
            beforeSend: function (){
            	$("#loading").show();
		$("#submit_btn").hide();
            }
            }).done(function(msg) {
                $("#loading").hide();
                $("#submit_btn").show();
                    var obj = jQuery.parseJSON (msg);
                    console.log(obj);
                if (obj.CODE_RETOUR == 0) {
                    $("#error").show();
                }
                else {
                    var html = "<div class='item' id='item' idParent='" + obj.ID_PARENT + "'>" + obj.PRENOM + " " + obj.NOM + "</div><div class='showEleve' id='" + obj.ID_PARENT + "'></div>";
                    $("#searchResult").append(html);
                    $('#createParent').bPopup().close();
				}
				$('div#item').click(function() {
					var idParent = $(this).attr("idParent");
					$("#" + idParent).html("");
					eleveSearch(idParent);
				});
		});
        }
    });
});